package com.zja.controller;

import com.zja.pojo.Grade;
import com.zja.pojo.Result;
import com.zja.service.impl.GradeServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/grade")
public class GradeController {
    @Autowired
    private GradeServiceImpl gradeService;

    @GetMapping("gradeList")
    public Result<List<Grade>> getGradeList(@RequestParam(required = false) String gradeId,
                                            @RequestParam(required = false) String gradeName){
        List<Grade> list = gradeService.getGradeList(gradeId,gradeName);
        if(list!=null){
            Result result = new Result<>(true,list);
            return  result;
        }else{
            Result result = new Result();
            result.setFlag(false);
            return result;
        }
    }

    @GetMapping("add")
    public Result add(@RequestParam(required = false) String gradeId,
                      @RequestParam(required = false) String gradeName){
        boolean flag = gradeService.add(gradeId,gradeName);
        Result result = new Result();
        result.setFlag(flag);
        return result;
    }

    @GetMapping("del")
    public Result del(@RequestParam String gradeId){
        boolean flag = gradeService.del(gradeId);
        Result result = new Result();
        result.setFlag(flag);
        return result;
    }
}
